{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install gym-jsbsim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install gym\n",
    "!pip install folium"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import gym\n",
    "import gym_jsbsim\n",
    "\n",
    "from gym_jsbsim.jsbsim_env import JSBSimEnv\n",
    "from gym_jsbsim.task import Task\n",
    "from gym_jsbsim.catalogs.catalog import Catalog as c\n",
    "from gym_jsbsim.envs.taxi_control_task import TaxiControlTask as Task\n",
    "#from gym_jsbsim.envs.heading_control_task import HeadingControlTask as Task\n",
    "\n",
    "\n",
    "import random\n",
    "import numpy as np\n",
    "import folium\n",
    "import copy\n",
    "\n",
    "from numpy.linalg import norm\n",
    "from numpy import array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#env1 = gym.make('GymJsbsim-TaxiapControlTask-v0')\n",
    "env1 = JSBSimEnv(Task)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "env1.reset()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# big action number\n",
    "ban = 10\n",
    "actions = []\n",
    "for i in range(ban):\n",
    "  actions.append([t[0] for t in env1.action_space.sample()])\n",
    "\n",
    "# one action permutation\n",
    "oap = copy.deepcopy(actions)\n",
    "\n",
    "random.shuffle(actions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "state1 = []\n",
    "\n",
    "state = env1.reset()\n",
    "state1.append([x[0] for x in state])\n",
    "\n",
    "for a in oap:\n",
    "    state, reward, done, info = env1.step(a)\n",
    "    state1.append([x[0] for x in state])\n",
    "    \n",
    "print(state1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10):\n",
    "    env1.reset()\n",
    "    # yet another action permutation \n",
    "    random.shuffle(actions)\n",
    "    #print(norm(action))\n",
    "    for a in actions:\n",
    "        state = env1.step(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "state2 = []\n",
    "\n",
    "state = env1.reset()\n",
    "state2.append([x[0] for x in state])\n",
    "\n",
    "for a in oap:\n",
    "    state, reward, done, info = env1.step(a)\n",
    "    state2.append([x[0] for x in state])\n",
    "    \n",
    "print(state2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(oap)):\n",
    "    d = np.asarray(state2[i]) - np.asarray(state1[i])\n",
    "    print(\"difference state {}: {}\".format(i, norm(d)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
